Jump to content
Larry Ullman's Book Forums

timveer

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by timveer

  1. Antonio & Larry, Thanks both for your responses. @Antonio - wow.... That OOP stuff looks really interesting. I'll have to spend some more time looking at OO for my own mySQL use and project development. Cheers, -t
  2. Thanks Larry, That's what I thought, but now I know for sure. Keep up the good writings. Cheers, -t EDIT: Hey Larry, quick thought. Is this applicable in both procedural and OOP approaches to using mysqli? Thanks -t
  3. Hey all, First time poster, several time owner (my bookshelf sags under the VisualQuickPro section) Trying to port over some code from mysql to mysqli, but ran into a snag (actually I just can't get my head around it...) I am used to, on an "includes()" function file (functions.inc), including my db connection scripts and several db related functions. For example, I have a section at the beginning of the functions.inc file: (note the code here is stripped and cleaned to be clearer) $connect = mysql_connect($tbl_hostname, $tbl_username, $tbl_password) ; $selectdb = mysql_select_db($tbl_database, $connect) ; Further down I call a function: function user_exists($user) { $total = mysql_query("SELECT COUNT(`user_id`) FROM `user` WHERE `user_name` = '{$user}'"); return (mysql_result($total, 0) == '1') ? true : false; } and it worked fine, however when I try to use mysqli I run into problems. Re-working the functions.inc file it now includes: $connect = mysqli_connect('localhost', 'root', 'password', 'users_db') ; and the function looks like: function user_exists($user) { $total = mysqli_query($connect, "SELECT COUNT(`user_id`) FROM `user` WHERE `user_name` = '{$user}'"); $row= mysqli_fetch_array($total); return ($row['COUNT(`user_id`)'] == '1') ? true : false; } But I keep getting a "Undefined variable: connect in the file... etc, etc" My question (to which I couldn't find a clear answer) - Do I need to include the database connector line inside every function calling to the db? function user_exists($user) { $connect = mysqli_connect('localhost', 'root', 'password', 'users_db'); $total = mysqli_query($connect, "SELECT COUNT(`user_id`) FROM `user` WHERE `user_name` = '{$user}'"); $row= mysqli_fetch_array($total); return ($row['COUNT(`user_id`)'] == '1') ? true : false; } Thanks for any pointers. -t
×
×
  • Create New...