开发者

PDO prepared statement problem

I m having a database 'books'

book_id     author          title
   1     O'Brien, Tim     MSXML3: A Comprehensive Guide
   2     O'Brien, Tim     Microsoft .NET: The Programming Bible
   3     Kress, Peter     Paradox Lost
   4     Knorr            Creepy Crawlies
   5     Thurman, Paula   Splish Splash

I m developing my database class using PDO. My pdo conn string is taking parameters: obj =new PDO("mysql:host = localhost; dbname = testing",root,'')


At last my class is sending query : $query(say)=SELECT * FROM books WHERE book_id = ? AND author = ?

here '?' represent the parameter marker for prepared query. when i m preparing my query like : $result = obj->prepare($query);

Saving the book_id and author in $param as : $param =array(1,Knorr);

Now i am executing it like: $result->execute($param);

Itz not working.Query not executing. 开发者_运维知识库After long research i tried query table name with the database name like: SELECT * FROM testing.books WHERE book_id = ? AND author = ? and executed..it was executing like butter and working...

Now the problem is y this is happening??..no article of pdo mentioned that it may also happen. Sumone please tell y i have to use the database name along wid table name???


Try it with the spaces stripped from your connection string:

obj =new PDO("mysql:host=localhost;dbname=testing",root,'')

It seems fairly likely to me that you're not being dropped into the "testing" database on connection, and I'm guessing the spaces in your connection string are confusing the PDO initialisation code, and leaving you in the default database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜