Created
January 3, 2014 10:36
-
-
Save solicomo/8235969 to your computer and use it in GitHub Desktop.
test mysql/sqlite/pdo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
mysql_connect("host","username","password") or die("Unable to Connect"); | |
mysql_select_db("dbname") or die("Could not open the db"); | |
$sql="select * from tablename"; | |
$result=mysql_query($sql); | |
while($row = mysql_fetch_array($result)) | |
{ | |
echo $row[0].' => '.$row[1]."\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dbh = new PDO('mysql:host=localhost;dbname=dbname;', 'username', 'password'); | |
$sql="select * from tablename"; | |
foreach ($dbh->query($sql) as $row) | |
{ | |
echo $row[0].' => '.$row[1]."\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dbh = new PDO('sqlite:test.sqlite'); | |
$sql='CREATE TABLE tab(key PRIMARY KEY, val)'; | |
$dbh->exec($sql); | |
$sql='INSERT INTO tab VALUES("k1", "v1")'; | |
$dbh->exec($sql); | |
$sql='INSERT INTO tab VALUES("k2", "v2")'; | |
$dbh->exec($sql); | |
$sql="select * from tab"; | |
foreach ($dbh->query($sql) as $row) | |
{ | |
echo $row[0].' => '.$row[1]."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment