Help - Search - Members - Calendar
Full Version: Pdo Mysql Driver
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
ochho
Hello,

I am new to zymic, and everything was fine until now..but I am wondering why is there no support for mySQL PDO?

the phpinfo() shows that sqlite, sqlite2 are available.. how come no mysql? "PDO drivers sqlite2, sqlite "

And this is the error I get on my site:

"ERRNO: 256 TEXT: could not find driver"

Thank you for the help.
Ed
Should be in now, please check smile.gif
ochho
Thank you for the quick reply. I am performing some tweaks on the database, and I will report back here once I know if it's working or not.

Regards,
ochho.
ochho
I am trying to change the database through php script, because phpmyadmin doesnt work.

Everything was fine while creating Tables and populating data, but I can't create any SQL stored procedures, any idea why?

"Access denied for user 'prana_admin'@'localhost' to database 'prana_prana'"

I checked the info, and everything is good.. database="prana_prana", username="prana_admin" domain="prana.uuuq.com"

Here is the script:

CODE
<?php
$con = mysql_connect('localhost', 'prana_admin', '*****');

if(!$con){
echo 'Mysql did not connect: ' . mysql_error();
die();
}

$db_conn = mysql_select_db('prana_prana', $con);

if(!$db_conn){
echo mysql_error();
die();
} else {
echo 'Database selected <br />';
}

$sql = "CREATE PROCEDURE `catalog_get_categories_list`()
BEGIN
SELECT category_id, en_name, fr_name FROM category ORDER BY category_id;
END" ;

$query = mysql_query($sql);

if(!$query){
echo 'Table not created '.mysql_error();
die();
} else {
echo 'Table Created';
}
?>



EDIT: Resolved, Thank you Bread!
suryadharma
QUOTE(ochho @ Jun 15 2009, 02:17 AM) *
Hello,

I am new to zymic, and everything was fine until now..but I am wondering why is there no support for mySQL PDO?

the phpinfo() shows that sqlite, sqlite2 are available.. how come no mysql? "PDO drivers sqlite2, sqlite "

And this is the error I get on my site:

"ERRNO: 256 TEXT: could not find driver"

Thank you for the help.


Hello,
I'm new here, i have same problem with ochho.
The error i've got on my site:

Fatal error: Uncaught exception 'Exception' with message 'could not find driver' in /www/vndv.com/s/u/r/suryadharma/htdocs/config.php

'could not find driver' i think its mean the config file can't find PDO for Mysql

Thank's for the help
ikun
Hi,

I also have the problem.

I get :
ERROR 256: PDO/mysql is not installed

I check phpinfo. PDO is enabled with sqlite and sqlite2 drivers but no mysql driver.

Or is it possible to dynamically load the driver ?
Tell me if i am wrong, as I understand in other posts, it is not possible to have custom php.ini ?

Thanks for any help,

ikun,
ps :
i must tell i have really short experience in php.
i am trying to install phpgedview 4.2.2 with uses pdo mysql driver.
ikun
QUOTE(Bread @ Jun 15 2009, 02:52 AM) *
Should be in now, please check smile.gif


Still not finding mysql enabled in the pdo support section of phpinfo.
Only sqlite, sqlite2 pdo support enabled.

Did an update disable pdo mysql support since june ?

Thanks for any help,

ikun
giorgiosironi
I'd like to bump this thread because I have registered today and I received the "could not find driver" error when I uploaded my files which uses PDO (my first page: http://nospam.zymichost.com/). I think the PDO mysql driver it's really important in most php applications, is it not present for a reason?
scout
Let me start by saying, I'm very new to coding and I am trying to learn on my own (books and Internet no schooling).

With that being said, on to my problem......

I'm trying to add a blog to my web site from a book, PHP for Absolute Beginners by Jason Lengstorf, and so far all I get is errors.

I've added the code that I have so far along with the errors below.

According to the book, I am more than far enough along for it to work in a most basic form, but it doesn't.

I have checked all the code several times to make sure that I had no typing errors (fixed the ones I had) and it still doesn't work.

I have the SQL table setup like the book said, along with the future additions from later in the book...



***index.php***
CODE
<?php

/*
* Include the necessary files
*/
include_once 'inc/functions.inc.php';
include_once 'inc/db.inc.php';

//Open a database connection
$db = new PDO(DB_INFO, DB_USER, DB_PASS);

/*
*Figure out what page is being requested (default is blog)
*Perform basic sanitization on the variable as well
*/
if(isset($_GET['page']))
{
$page = htmlentities(strip_tags($_GET['page']));
}
else
{
$page = 'blog';
}

//Determine if an entry ID was passed in the URL
$id = (isset($_GET['id'])) ? (int) $_GET['id'] : NULL;

//Load entries
$e = retrieveEntries($db, $page, $id);

//Get the fulldisp flag and remove it from the array
$fulldisp = array_pop($e);

//Sanitize the entry data
$e = sanitizeData($e);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="/css/default.css" type="text/css" />

<title>Simple Blog</title>

</head>

<body>

<h1>Simple Blog Application</h1>

<div id="entries">

<?php

//If the full display flag is set, show the entry
if($fulldisp==1)
{

?>

<h2><?php echo $e['title'] ?></h2>
<p><?php echo $e['entry'] ?></p>
<p class="backlink">
<a href="./">Back to Latest Entries</a>
</p>


<?php

} //End the if statement


//If the full display flag is 0, format linked entry titles

else
{
//Loop through each entry
foreach($e as $entry){

?>

<p>
<a herf="?id=<?php echo $entry['id'] ?>">
<?php echo $entry['title'] ?>

</a>
</p>

<?php

} // End the foreach loop
}//End the else

?>


<p class="backlink">

<a href="/admin.php">Post a New Entry</a>
</p>

</div>

</body>

</html>


***admin.php***
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

<link rel="stylesheet" href="css/default.css" type="text/css" />

<title>Simple Blog</title>

</head>

<body>
<h1>Simple Blog Application</h1>

<form method="post" action="inc/update.inc.php">
<fieldset>
<legend>New Entry Submission</legend>
<label>Title
<input type="text" name="title" maxlength="150" />
</label>
<label>Entry
<textarea name="entry" cols="45" rows="10"></textarea>
</label>
<input type="submit" name="submit" value="Save Entry" />
<input type="submit" name="submit" value="Cancel" />
</fieldset>
</form>
</body>

</html>


***functions.inc.php***
CODE
<?php

function retrieveEntries($db, $page, $url=NULL)
{

/*
*If an entry ID was supplied, load the associated entry
*/
if(isset($id))
{
$sql = "SELECT title, entry
From entries
WHERE id=?
LIMIT 1";
$stmt = $db->prepare($sql);
$stmt->execute(array($_GET['id']));

//Save the returned entry array
$e = $stmt->fetch();

//Set the fulldisp flag for a single entry
$fulldisp = 1;
}

/*
*If no entry ID was supplied, load all entry titles for the page
*/
else
{
$sql = "SELECT id, page, title, entry
FROM entries
WHERE page=?
ORDER BY created DESC";
$stmt = $db->prepare($sql);
$stmt->execute(array($page));

$e = NULL; //Declare the variable to avoid errors

//Loop through returned results and store as an array
while($row = $stmt->fetch()){
$e[] = $row;
}

//Set the fulldisp flag for multiple entries
$fulldisp = 0;

/*
*If no entries were returned, display a default
*message and set the fulldisp flag to display a
*single entry
*/
if(!is_array($e))
{
$fulldisp = 1;
$e = array(
'title' => 'No Entries Yet',
'entry' => '<a href="/admin.php">Post an entry!</a>'
);
}

}

//Add the $fulldisp flag to the end of the array
array_push($e, $fulldisp);

return $e;
}

function sanitizeData($data)
{
//If $data is not an array, run strip_tags()
if(!is_array($data))
{
//Remove all tags except <a> tags
return strip_tags($data, "<a>");
}

//If data is an array, process each element
else
{
//Call sanitizeData recursively for each array element
return array_map('sanitizeData' , $data);
}

}

?>


***update.inc.php***
CODE
<?php

if($_SERVER['REQUEST_METHOD']=='POST'
&& $_POST['submit']=='Save Entry'
&& !empty($_POST['title'])
&& !empty($_POST['entry']))
{

//Include database credentials and connect to the database
include_once 'db.inc.php';
$db = new PDO(DB_INFO, DB_USER, DB_PASS);

//Save the entry into the database
$sql = "INSERT INTO entries (title, entry) VALUES (?, ?)";
$stmt = $db->prepare($sql);
$stmt->execute(array($title, $entry));
$stmt->closeCursor();

//Get the ID of the entry we just saved
$id_obj = $db->query("SELECT LAST_INSERT_ID()");
$id = $id_obj->fetch();
$id_obj->closeCursor();

//Send the user to the new entry
header('Location: ../?id='.$id[0]);
exit;

}

//If both conditions aren't met, sends the user back to the main page
else
{
header('Location: ../');
exit;
}

?>




***db.inc.php***
CODE
<?php

define('DB_INFO', 'mysql:host=localhost;dbname=simpleblog');
define('DB_USER', 'root');
define('DB_PASS', ' ');

?>


*****didn't include CSS file*****


The error I get when I 'save entry' on the ADMIN page....

QUOTE
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /www/zxq.net/m/y/f/myfirstsite/htdocs/web page stuff/simpleblog/inc/update.inc.php:11 Stack trace: #0 /www/zxq.net/m/y/f/myfirstsite/htdocs/web page stuff/simpleblog/inc/update.inc.php(11): PDO->__construct('mysql:host=loca...', 'root', ' ') #1 {main} thrown in /www/zxq.net/m/y/f/myfirstsite/htdocs/web page stuff/simpleblog/inc/update.inc.php on line 11


.....and save entry or cancel with the fields left blank.....

QUOTE
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /www/zxq.net/m/y/f/myfirstsite/htdocs/web page stuff/simpleblog/index.php:10 Stack trace: #0 /www/zxq.net/m/y/f/myfirstsite/htdocs/web page stuff/simpleblog/index.php(10): PDO->__construct('mysql:host=loca...', 'root', ' ') #1 {main} thrown in /www/zxq.net/m/y/f/myfirstsite/htdocs/web page stuff/simpleblog/index.php on line 10



.....as well as the error that I get just by going to the INDEX page.......

QUOTE
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /www/zxq.net/m/y/f/myfirstsite/htdocs/web page stuff/simpleblog/index.php:10 Stack trace: #0 /www/zxq.net/m/y/f/myfirstsite/htdocs/web page stuff/simpleblog/index.php(10): PDO->__construct('mysql:host=loca...', 'root', ' ') #1 {main} thrown in /www/zxq.net/m/y/f/myfirstsite/htdocs/web page stuff/simpleblog/index.php on line 10



What am I doing wrong?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.