PHP Yii Database Connection Tutorial with Examples

PHP Yii Database Connection Tutorial with Examples

Today, We want to share with you PHP Yii Database Connection Tutorial with Examples.
In this post we will show you Yii Database Access, hear for php – configuring database connection in Yii framework we will give you demo and example for implement.
In this post, we will learn about Connect To A MySQL Database With Yii with an example.

PHP Yii Application Configuration main DB (config/main.php)

Yii Database Connection – Sqlite Database

The PHP Based Frameworks The Yii Database To connect the Mysql sqlite db with web application, I should the folder Information of database.

'db'=>array(
    'connectionString' => 'sqlite:'.dirname(__FILE__).'/../pakainfo/livepaka.db',
),

Yii Database Connection – Mysql Database

The PHP Based Frameworks The Yii Database To connect the mysql db with web simple application, I should the Eneter your “localhost” hosting Information, database name(pakainfo), username(atmiya), and password(Jayu#$54#*&*#PakaInfo).

'db'=>array(
        'connectionString' => 'mysql:host=localhost;dbname=pakainfo',
        'emulatePrepare' => true,
        'username' => 'atmiya',
        'password' => 'Jayu#$54#*&*#PakaInfo',
        'charset' => 'utf8',
        ),

Excute Query

$clients = Yii::app()->db->createCommand()
        ->select('cname, cpass')
        ->from('user_mst')
        ->where('id=:id', array(':id'=>1))
        ->queryRow();

PHP Yii CDbConnection – Yii Database Connection

The Yii PHP based Frameworks CDbConnection display a connection to a simple database.

$connection=new CDbConnection($hosting,$username,$password);
$connection->active=true;

PHP Yii Excute Query

$sqlStatement="select cname, cpass from user_mst where id=:id limit 1";
$yii_conn=$connection->createCommand($sqlStatement);
$yii_conn->bindParam(':id',$cid);
$yii_conn->execute();  
$user=$yii_conn->query();

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Yii Database Connection.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel 6 JQuery Ajax Post Request Example
  2.   ng-options to Set Default Value using Angular Example
  3.   Modal Popup Form Submit in Ajax with PHP and Mysql
  4.   Yii Framework Introduction and Hello World Tutorial
  5.   jQuery Validation Email Mobile password Regular Expression
  6.   Loop Binding in Vue.js With V-for
  7.   Laravel Drop all tables with MySQL
  8.   Simple Vue 2.0 Hello World Example
  9.   PHP Jquery Ajax Upload Multiple Images with Preview
  10.   ng-model Directive using Angular Example