Jump to content

redsmurph

Members
  • Posts

    35
  • Joined

  • Last visited

Everything posted by redsmurph

  1. I never use mysqli, so I wasn't aware of differences, but this seems to explain it: link: A link identifier returned by mysqli_connect() or mysqli_init() So you need to add $connect to both esc and sqlinsert and add $connect to the call of esc. function esc($connect, $text) { return mysql_real_escape_string($connect, $text); } I hope you can "connect the dots".
  2. The principle: $echo = false; while (!feof($handle)) { $buffer = fgets($handle); if (found start pattern) $echo = true; if (found end pattern or a new start pattern?) $echo = false; if ($echo) echo $buffer; } You know better than me what determines the end of the sequence. Cheers, Anders
  3. You also need to take explicit action when the query returns false. You can't just assume it will always succeed.
  4. After a search hit you need to set a state variable that you then test for to see if further lines should be output for each loop. This variable should be cleared when you reach the end of a group of lines (the next Check or Likely?). While the state variable is set you echo all lines. You might run into the problem of reading too much, but the above is principally what you need to do.
  5. Replace: sqlquery --> mysqli_query mysql_insert_id --> mysqli_insert_id Then run the function like this: $id_appointments = sqlinsert('appointments', array('username' => $username, ...)); or create the array first and put it in the call: $values = array(); $values['username'] = $username; ... $id_appointments = sqlinsert('appointments', $values); If you want to test on the result: if ($id_appointments !== false) { // It worked ! } else { // It failed ! } Cheers, Anders
  6. I assume you already have the data in a database table. I'd keep it the way you have it: one row per city. First thing I would do would be to index the ZIP row for increased SELECT performance. Then I would run a SELECT on the ZIP code and get all the rows back for that ZIP code and merge the city names in real time, if now you want to show the city names at all. If you really want to merge I'd advise you to read from one table (as per above), merge in PHP and then write to another table. Otherwise you are in for a disaster. Cheers, Anders
  7. I read the conditions for hosting at PHP Fog, and they state that I can't use session variables as such variables are not copied between servers. Therefore I changed session variables for login info, language selection etc to cookies. Hence my own code is now free from session varibables, but Zend that I use for e.g. OAuth is not. Is it typical that cloud hosting providers disallow session variables for the above reason, or are there others that can handle such replication between servers? If not, is work going on to remove use of session variables from popular frameworks? Cheers, Anders
  8. My take on SQL is to abstract it whenever possible, as you always have to escape your values and the SQL syntax is generally easy to get wrong, without any static syntax control what-so-ever. sqlinsert below takes $values as an associative array of column values. sqlquery is just mysql_query with error reporting via e-mail, so you can directly replace it with mysql_query. You can thank me later. Cheers, Anders function esc($text) { return mysql_real_escape_string($text); } function sqlinsert($table, $values) { $len = sizeof($values); if ($len > 0) { $query = "INSERT INTO $table ( "; $first = true; foreach ($values as $column => $value) { $query .=!$first ? ', ' : ''; $first = false; $query .= "`$column`"; } $query .= ' ) VALUES ( '; $first = true; foreach ($values as $column => $value) { $query .=!$first ? ', ' : ''; $first = false; $query .= "'" . esc($value) . "'"; } $query .= ' )'; sqlquery($query); return mysql_insert_id(); } return false; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.