Jump to content

PHP update


mikeb2017

Recommended Posts

Hello there,

 

I like to start with sorry i'm new and i have an issue related to old php and the new PHP. I made this coding in dreamweaver years ago and now after the php update i does not work anymore. and i just cannot figure out why. i hope somebody can help me rewrite this ?.. many thanks

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

if (PHP_VERSION < 6) {

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {

case "text":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "long":

case "int":

$theValue = ($theValue != "") ? intval($theValue) : "NULL";

break;

case "double":

$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

break;

case "date":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "defined":

$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

break;

}

return $theValue;

}

}

$colname_rsDate = "-1";

if (isset($_POST['date1'])) {

$colname_rsDate = $_POST['date1'];

}

mysql_select_db($database_bowlingl, $connbowling);

$query_rsDate = sprintf("SELECT * FROM FILES WHERE DATUM = %s", GetSQLValueString($colname_rsDate, "date"));

$rsDate = mysql_query($query_rsDate, $connbowling) or die(mysql_error());

$row_rsDate = mysql_fetch_assoc($rsDate);

$totalRows_rsDate = mysql_num_rows($rsDate);

?>

Link to comment
Share on other sites

PDO?  You are worried about the use of PDO in place of mysql_* functions?  You are seriously mis-informed.  Using PDO is pretty much no different than using some string related functions or some File upload functions or some file-read-write ones.  It's just a set of functions!  

 

To be using the switch to pdo as your excuse to hang it up is just plain wrong.  The biggest problem you have is re-writing your long, way too elaborate code using some smarts and the more current functions available.  That's where you need to knuckle down.  PDO is like switching from chocolate to vanilla.  Jeez!!

 

This is pdo in a snap!

$q = "some query statement using substitute parameters for a prepared query";
$qst = $pdo->prepare($q);
$parms = array(':fld1'=> $value1,
                         ':fld2'=> $value2,
                        ':fld3'=> $value3);
$result = $qst->execute($parms);
if (!$result)
{
   (some code to recognize the error occurred and end gracefully - same as with mysql_* functions)
}
//  check if any rows were found?
if ($qst->rowCount() ==0)
{
  (some code to run if there are no results - same as with mysql_* functions)
}
else
{
     while($row = $qst->fetch(PDO::FETCH_ASSOC))  // same as using mysql_* functions
     {
         (do things with the query results - same as with mysql_* functions)
     }
}
 

 

And That's PDO.

 

You might want to read up on what are prepared queries are and why you should get used to using them and using named substitute parms instead of the ? ones.

 

(edit - I hate when the forum changes what I typed with extra blank lines in my post.  Why oh why?)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.