I have an old mysql code which I want to convert into PHP data object but I cant find on the web how this can be done, any help?
$num = mysql_num_rows($result = mysql_query($query));
while($row = mysql_fetch_array($result))
{
...
}
$query is a SELECT statement.
UPDATE:
My code is only showing the message “could not find driver” and notihng else, it isn’t showing form code or anything like that. What am i doing wrong in my PDO? I know database, hostname, username and password are correct so it should be able to show form and then let me connect to DB.
<?php
session_start();
$hostname = 'localhost';
$username="xxx";
$password="xxx";
$database="mobile_app";
try {
$dbh = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
?>
,,, //Form Code is in here
<?php
if (isset($_POST['submit'])) {
$query = "
SELECT * FROM Teacher t
WHERE
(t.TeacherUsername = '".mysql_real_escape_string($teacherusername)."')
AND
(t.TeacherPassword = '".mysql_real_escape_string($teacherpassword)."')
";
$loged = false;
foreach ($dbh->query($sql) as $row)
{
,,,, //results for each row
}
$dbh = null;
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
1 Answer