By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,420 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Mysql without Pear DB

P: 2
Hello!
I would like to ask your help, i have founded a great code here: http://www.jamescaws.co.uk/2008/07/dynamically-count-exit-link-clicks-throughs-using-javascript-php/

but it uses Pear DB for the database connection. the problem is that it don't works, actually the php don't writes anything in the table and i don't get any error when i add the
Expand|Select|Wrap|Line Numbers
  1. if (PEAR::isError($db)) {
  2. die($db->getMessage());}
code, so not the connection...

Then i tried a simple insert (a Pear DB one, from the pear manual... )
it looks like this:
Expand|Select|Wrap|Line Numbers
  1. $res =& $db->query("INSERT INTO ct_Links (hash, url) VALUES (v, something)");
there's no succes so, maybe somebody can help to rewrite the code to use only simple mysql and php without the pear package... please:D

the connect is simple. but there are some code i don't really no how to transform:
Expand|Select|Wrap|Line Numbers
  1. $db->setFetchMode(DB_FETCHMODE_ASSOC);
  2.  
  3. function local_getLinkID($db, $debugObj, $sHash) {
  4.     $sql = sprintf('SELECT linkID FROM ct_Links WHERE hash = %s', $db->quoteSmart($sHash));
  5.  
  6.     $debugObj->output("local_getLinkID($db, $debugObj, $sHash) : $sql");
  7.  
  8.     $iID = $db->getOne($sql);
  9.  
  10. function local_logNewLink($db, $debugObj, $sHash, $sURL) {
  11.     $sql = sprintf('INSERT INTO ct_Links (hash, url) VALUES (%s, %s)',
  12.         $db->quoteSmart($sHash),
  13.         $db->quoteSmart($sURL)
  14.     );
  15.  
  16.     $debugObj->output("local_logNewLink($db, $debugObj, $sHash, $sURL) : $sql");
  17.  
  18.     $db->query($sql);
  19.  
  20.     return $db->getOne('SELECT LAST_INSERT_ID()');
  21. }
  22.  
  23.  
  24. function local_logLinkClick($db, $debugObj, $iLinkID, $sIP, $sUserAgent) {
  25.     $sql = sprintf('INSERT INTO ct_Log (linkID, ip, useragent) VALUES (%d, INET_ATON(%s), %s)',
  26.         $iLinkID,
  27.         $db->quoteSmart($sIP),
  28.         $db->quoteSmart($sUserAgent)
  29.     );
  30.  
  31.     $debugObj->output("local_logLinkClick($db, $debugObj, $iLinkID, $sIP, $sUserAgent) : $sql");
  32.  
  33.     $db->query($sql);
thanks for any help!!
Sep 1 '08 #1
Share this Question
Share on Google+
2 Replies


Atli
Expert 5K+
P: 5,058
Hi.

You shouldn't have any trouble changing your code to use the MySQLI extension.
Any decent host should support it.

There are excellent examples of how to use it in the mysqli_query section of the manual.
Sep 2 '08 #2

P: 2
ok thank you very much i will try
Sep 2 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.