pdo mysql php code example
Example 1: php mysql pdo connection
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
Example 2: php query pdo
<?php
$sql = 'SELECT name, color, calories FROM fruit ORDER BY name';
foreach ($conn->query($sql) as $row) {
print $row['name'] . "\t";
print $row['color'] . "\t";
print $row['calories'] . "\n";
}
?>
Example 3: php pdo sql server connect
$db = new PDO("sqlsrv:Server=YouAddress;Database=YourDatabase", "Username", "Password");
Example 4: pdo example
<?php
$dsn = "mysql:host=localhost;dbname=mydb";
$user = "user12";
$passwd = "12user";
$pdo = new PDO($dsn, $user, $passwd);
Example 5: PDO::MYSQL_ATTR_SSL_CA path of file
129 * Lists all models.
130 */
131 public function actionIndex()
132 {
133
134 $data = Yii::app()->dbJoomla->createCommand('SELECT * FROM MixanesDiaolou ORDER BY id DESC LIMIT 10')->queryAll();
135 var_dump($data);
136
137
138 $dataProvider=new CActiveDataProvider('Category');
139 $this->render('index',array(