FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » php PDO does not work
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: php PDO does not work [message #177292 is a reply to message #177281] Mon, 05 March 2012 09:23 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 03/03/2012 16:10, test japan escribió/wrote:
> i installed php and mysql on archlinux by pacman,
> and in phpinfo page, i can see the infomation about mysql& pdo_mysql
>
> in php.ini, i uncommented the following lines:
> extension=mysqli.so
> extension=mysql.so

As far as I know, these are unrelated to PDO.


> extension=pdo_mysql.so

Correct, this is the PDO driver for MySQL, though I don't really
understand why pdo_mysql actually showed up in phpinfo() if this line
was commented out :-?


> but when running the code below, the browser shows a blank page
> no result, even no error message.
>
> try {
> $dbh = new PDO("mysql:host=192.168.0.1;dbname=testdb", "username", "password");
> echo 'Connected to database!!';
> } catch (PDOException ex) {
> echo $ex->getMessage();

Assuming there's a PHP start tag, you should be getting this:

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE

I suggest you configure your development box to display all possible
errors. You have several ways to do so:

1. Edit your "php.ini" file:

error_reporting = E_ALL | E_STRICT
display_errors = On

2. Put this on top of your script:

<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', TRUE);

3. If PHP runs as Apache module, you can also use an `.htaccess` file:

# You cannot use PHP constants here
php_value error_reporting -1
php_flag display_errors on

This is not specifically related to PDO, it's how PHP error reporting
works in general.



Additionally, PDO will not throw exceptions unless you tell it to
because the default mode is PDO::ERRMODE_SILENT:

http://es2.php.net/manual/en/pdo.error-handling.php

This also implies that you cannot use exceptions to capture connection
errors unless you set PDO::ERRMODE_EXCEPTION in the constructor.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: Mac OS X how to install php / yaml ?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 17:12:46 GMT 2024

Total time taken to generate the page: 0.05314 seconds