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?)

Edited by ginerjm
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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