Jump to content

Recommended Posts

The biggest change will be to your database access. If you use mysql_* functions you will find they no longer exist in version 7.

You will need to rewrite all your db code to use either

  • mysqli, or
  • PDO

As you re going to have to change and relearn I would recommend you take the PDO path. The name "mysqli" may look like "mysql" but they are different animals and there is more to recoding than just adding "i".

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606135
Share on other sites

the php documentation lists the major changes going between each version - https://www.php.net/manual/en/appendices.php

if there's not a huge amount of code, you could just post the entire project somewhere (github) and someone can review and list what things in it will need to be changed.

agree with @benanamen, you should be updating to the latest php version, not php7.

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606149
Share on other sites

Okay. Is this what I am going to have to do?

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

define ('HOSTNAME1', 'mysql09.iomart.com'); 
define ('USERNAME1', 'otoogc692');
define ('PASSWORD1', 'mauritius');
define ('DATABASE1', 'otoogc692');
define ('SUGARCAIN' , 1);
define ('BLANTYRE' , 2);

function connectDB()
{
    $host = HOSTNAME1;
    $user = USERNAME1;
    $pass = PASSWORD1;
    $MyDB = DATABASE1;

// OLD
//mysql_connect($host, $user, $pass);
//mysql_select_db($data, $link);

// NEW. Got this a StackOverflow forum
$conn = new PDO("mysql:host=$host; dbname=$MyDB; charset=UTF8", $user, $pass, [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
]);
}

function Contracts($id)
{
	connectDB();
	
	$qList = $pdo->query("SELECT * FROM Contracts");
	return $qList;
	// Calling routine uses	 while ($row = $qList->fetch()) {
	// echo $row['name']."<br />\n"; }
}

// https://phpdelusions.net/pdo_examples
?>

 

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606151
Share on other sites

This should work? but get

Notice: Undefined variable: pdo in /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/PDOtest2.php on line 29

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

define ('HOSTNAME1', 'mysql09.iomart.com'); 
define ('USERNAME1', 'otoogc692');
define ('PASSWORD1', 'mauritius');
define ('DATABASE1', 'otoogc692');
define ('SUGARCAIN' , 1);
define ('BLANTYRE' , 2);

function connectDB()
{
    $host = HOSTNAME1;
    $user = USERNAME1;
    $pass = PASSWORD1;
    $MyDB = DATABASE1;

	$conn = new PDO("mysql:host=$host; dbname=$MyDB; charset=UTF8", $user, $pass, [
    		PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    		PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
]);
}


function Contracts()
{
	connectDB();	
	$qList = $pdo->query("SELECT * FROM EC_event WHERE Date = '2020-10-20 17:55:00'");
	return $qList;
	// Calling routine uses	 while ($row = $qList->fetch()) {
	// echo $row['name']."<br />\n"; }
}

$Result = Contracts();
$MyRow = $row = $qList->fetch();
echo "Value = " . $MyRow['Venue'];
?>

 

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606152
Share on other sites

The variable $pdo has not been defined inside the functioon. You need to pass it to the function when you call it.

function Contracts($pdo)
{
	// connectDB();	
	$qList = $pdo->query("SELECT * FROM EC_event WHERE Date = '2020-10-20 17:55:00'");
	return $qList;
	// Calling routine uses	 while ($row = $qList->fetch()) {
	// echo $row['name']."<br />\n"; }
}

$Result = Contracts($pdo);

Don't connect every time you perform a query.

Connect once at the top of the script, storing the connection in $pdo.

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606153
Share on other sites

21 minutes ago, Paul-D said:
    		PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    		PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ

when you make the connection, you should set the error mode to exceptions, which is what you are doing, set emulated prepared queries to false, you need to add this, and set the default fetch mode to assoc, you are setting it to obj, which is not what you are using in the example code and is probably not what your existing code is using  with the fetched data, which will require you to make even more changes to your existing code.

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606154
Share on other sites

Okay. I have this code which results in 

Notice: Undefined variable: conn in /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/PDOtest2.php on line 25

Fatal error: Call to a member function query() on a non-object in /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/PDOtest2.php on line 25

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

define ('HOSTNAME1', 'mysql09.iomart.com'); 
define ('USERNAME1', 'otoogc692');
define ('PASSWORD1', 'mauritius');
define ('DATABASE1', 'otoogc692');

$host = HOSTNAME1;
$user = USERNAME1;
$pass = PASSWORD1;
$MyDB = DATABASE1;

$conn = new PDO("mysql:host=$host; dbname=$MyDB; charset=UTF8", $user, $pass, [
		PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
		PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
]);

$Result = Contracts();
$MyRow = $row = $Result->fetch();
echo "Value = " . $MyRow['Venue'];

function Contracts()
{	
	$qList = $conn->query("SELECT * FROM EC_event WHERE Date = '2020-10-20 17:55:00'");
	return $qList;
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606164
Share on other sites

2 hours ago, Paul-D said:

Okay. I have this code which results in 

Notice: Undefined variable: conn in /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/PDOtest2.php on line 25

You've been told how to fix that.

If you ignore the information given to you then no there is no point in your posting or our answering

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606166
Share on other sites

Have made alterations from the https://phpdelusions.net/ examples. Still get 

Undefined variable: conn in /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/PDOtest2.php on line 26

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

define ('HOSTNAME1', 'mysql09.iomart.com'); 
define ('USERNAME1', 'otoogc692');
define ('PASSWORD1', 'mauritius');
define ('DATABASE1', 'otoogc692');

$host = HOSTNAME1;
$user = USERNAME1;
$pass = PASSWORD1;
$MyDB = DATABASE1;

$conn = new PDO("mysql:host=$host; dbname=$MyDB; charset=UTF8", $user, $pass, [
		PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
		PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
		PDO::ATTR_EMULATE_PREPARES   => false,
]);

$Result = Contracts();
$MyRow = $Result->fetch();
echo "Value = " . $MyRow['Venue'];

function Contracts()
{	
	$qList = $conn->query("SELECT * FROM EC_event WHERE ID = 2");
	return $qList;
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606167
Share on other sites

16 hours ago, Barand said:

The variable $pdo has not been defined inside the functioon. You need to pass it to the function when you call it.

Except fot the variable name ($pdo -> $conn) this is exactly the same problem that I answered earlier. If you are going to keep repeating the same question then I am going to close this thread.

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606168
Share on other sites

Have made alterations from the https://phpdelusions.net/ examples. Still get 

Undefined variable: conn in /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/PDOtest2.php on line 26

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

define ('HOSTNAME1', 'mysql09.iomart.com'); 
define ('USERNAME1', 'otoogc692');
define ('PASSWORD1', 'mauritius');
define ('DATABASE1', 'otoogc692');

$host = HOSTNAME1;
$user = USERNAME1;
$pass = PASSWORD1;
$MyDB = DATABASE1;

$conn = new PDO("mysql:host=$host; dbname=$MyDB; charset=UTF8", $user, $pass, [
		PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
		PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
		PDO::ATTR_EMULATE_PREPARES   => false,
]);

$Result = Contracts();
$MyRow = $Result->fetch();
echo "Value = " . $MyRow['Venue'];

function Contracts()
{	
	$qList = $conn->query("SELECT * FROM EC_event WHERE ID = 2");
	return $qList;
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606169
Share on other sites

I did say that I am out of my depth here but if you mean that you close the thread then do so.  I am passing it EVERY WHERE NOW. I am asking for help. You could politly tell me this is what you need to do. No chance of that.

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

define ('HOSTNAME1', 'mysql09.iomart.com'); 
define ('USERNAME1', 'otoogc692');
define ('PASSWORD1', 'mauritius');
define ('DATABASE1', 'otoogc692');

$host = HOSTNAME1;
$user = USERNAME1;
$pass = PASSWORD1;
$MyDB = DATABASE1;

$conn = new PDO("mysql:host=$host; dbname=$MyDB; charset=UTF8", $user, $pass, [
		PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
		PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
		PDO::ATTR_EMULATE_PREPARES   => false,
]);

$Result = Contracts($conn);
$MyRow = $Result->fetch();
echo "Value = " . $MyRow['Venue'];

function Contracts($conn)
{	
	$qList = $conn->query("SELECT * FROM EC_event WHERE ID = 2");
	return $qList;
}
?>

 

 

 

Edited by Paul-D
Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606170
Share on other sites

I do not have a $pdo in my code ANYWHERE.. I do have a $conn as in $conn = new PDO ( ...

$conn is a connection object is it not. Where is $pdo in my code.

The variable $pdo can not be defined in a function if it does not exsist. I am using $conn as an obcect as in $con = NEW

Edited by Paul-D
Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606172
Share on other sites

You are looking at VERY OLD CODE. Look for a $pdo defined as an object in this code. I am doing exactly as you said using $conn. Look at the code I am supplying NOW. I never defined $pdo as an object. Where has $pdo come from?

$conn = NEW PDO() makes $conn an object not a $pdo.

$conn = new PDO("mysql:host=$host; dbname=$MyDB; charset=UTF8", $user, $pass, [
		PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
		PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
		PDO::ATTR_EMULATE_PREPARES   => false,
*****
$Result = Contracts($conn);

****
function Contracts($conn)
{	
	$qList = $conn->query("SELECT * FROM EC_event WHERE ID = 2");
	return $qList;
}
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

define ('HOSTNAME1', 'mysql09.iomart.com'); 
define ('USERNAME1', 'otoogc692');
define ('PASSWORD1', 'mauritius');
define ('DATABASE1', 'otoogc692');

$host = HOSTNAME1;
$user = USERNAME1;
$pass = PASSWORD1;
$MyDB = DATABASE1;

$conn = new PDO("mysql:host=$host; dbname=$MyDB; charset=UTF8", $user, $pass, [
		PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
		PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
		PDO::ATTR_EMULATE_PREPARES   => false,
]);

$Result = Contracts($conn);
$MyRow = $Result->fetch();
echo "Value = " . $MyRow['Venue'];

function Contracts($conn)
{	
	$qList = $conn->query("SELECT * FROM EC_event WHERE ID = 2");
	return $qList;
}
?>

 

Edited by Paul-D
Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606173
Share on other sites

28 minutes ago, Paul-D said:

Where has $pdo come from?

You tell us. You used it in one of the first sets of code that you posted. You used $pdo and I told you the error was because it wasn't defined in the function and, therefore, you needed to pass it to the function.

The problems you are currently having is nothing to do with PHP version or database access. It is a lack of basic knowledge by you on how to use use php functions and variables (variable scope)

Link to comment
https://forums.phpfreaks.com/topic/315970-php-version-5445/#findComment-1606176
Share on other sites

Guest
This topic is now 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.