Welcome! Log In Create A New Profile

Advanced

[PHP] Deprecated features in PHP 5.5.x

Posted by Release Edl 
Release Edl
[PHP] Deprecated features in PHP 5.5.x
December 07, 2015 02:10PM
Hi people,

How can I use the mysqli function to substitute of mysql ?

I need to change an old script that uses mysql.

The script::

<?php

include(conexao.php");
$id = $_GET['id'];
$conexao = mysql_connect('host', 'user', 'pass');

if(!$conexao)

die("Error: " . mysql_error());

mysql_select_db($db) or die("Error: " . mysql_error());

$SQL = "SELECT * FROM portfolio WHERE id='$id' ORDER BY id DESC LIMIT 1";

$query = mysql_query($SQL);

while($x = mysql_fetch_array($query)) {

?>

Thanks in advance for any help.

Paulo


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Torsten Rosenberger
Re: [PHP] Deprecated features in PHP 5.5.x
December 07, 2015 02:20PM
Hello

Am Montag, den 07.12.2015, 11:07 -0200 schrieb Release Edl:
> Hi people,
>
> How can I use the mysqli function to substitute of mysql ?
>
> I need to change an old script that uses mysql.
>
> The script::
>
> <?php
>
> include(conexao.php");
> $id = $_GET['id'];
> $conexao = mysql_connect('host', 'user', 'pass');
>
> if(!$conexao)
>
> die("Error: " . mysql_error());
>
> mysql_select_db($db) or die("Error: " . mysql_error());
>
> $SQL = "SELECT * FROM portfolio WHERE id='$id' ORDER BY id DESC LIMIT 1";
>
> $query = mysql_query($SQL);
>
> while($x = mysql_fetch_array($query)) {
>
> ?>

http://de.php.net/manual/en/book.mysqli.php

take a look in the manual.

most functions are the same but with mysqli in front.

$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");

mysqli_select_db ( $link , $db );
mysqli_query ( $link ,.....)

so you have to rewrite the mysql with mysqli and add the connection to
all other functions


BR/Torsten




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Release Edl
Re: [PHP] Deprecated features in PHP 5.5.x
December 07, 2015 02:50PM
Perfect, Torsten!

Now it works properly:

<?php

include("conexao.php");
$id = $_GET['id'];
$conexao = mysqli_connect($host,$user,$pass,$db);

if(!$conexao)

die("Error: " . mysqli_error());

mysqli_select_db($conexao,$db) or die("Error: " . mysqli_error());

$SQL = "SELECT * FROM portfolio WHERE id='$id' ORDER BY id DESC LIMIT 1";

$query = mysqli_query($conexao,$SQL);

while($x = mysqli_fetch_array($query)) {

?>

Thanks a lot.
"Torsten Rosenberger" <[email protected]> escreveu na mensagem
news:[email protected]..
> Hello
>
> Am Montag, den 07.12.2015, 11:07 -0200 schrieb Release Edl:
>> Hi people,
>>
>> How can I use the mysqli function to substitute of mysql ?
>>
>> I need to change an old script that uses mysql.
>>
>> The script::
>>
>> <?php
>>
>> include(conexao.php");
>> $id = $_GET['id'];
>> $conexao = mysql_connect('host', 'user', 'pass');
>>
>> if(!$conexao)
>>
>> die("Error: " . mysql_error());
>>
>> mysql_select_db($db) or die("Error: " . mysql_error());
>>
>> $SQL = "SELECT * FROM portfolio WHERE id='$id' ORDER BY id DESC LIMIT 1";
>>
>> $query = mysql_query($SQL);
>>
>> while($x = mysql_fetch_array($query)) {
>>
>> ?>
>
> http://de.php.net/manual/en/book.mysqli.php
>
> take a look in the manual.
>
> most functions are the same but with mysqli in front.
>
> $link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
>
> mysqli_select_db ( $link , $db );
> mysqli_query ( $link ,.....)
>
> so you have to rewrite the mysql with mysqli and add the connection to
> all other functions
>
>
> BR/Torsten
>
>
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
Re: [PHP] Deprecated features in PHP 5.5.x
December 07, 2015 03:40PM
mysql_ functions were removed because of insecurities (like in your code,
you are not escaping your parameters and is very hackable). I would advise
on using prepared queries in mysqli_ instead of raw queries:

http://php.net/manual/en/mysqli.prepare.php

On Mon, Dec 7, 2015 at 8:44 AM, Release Edl <[email protected]>
wrote:

> Perfect, Torsten!
>
> Now it works properly:
>
> <?php
>
> include("conexao.php");
> $id = $_GET['id'];
> $conexao = mysqli_connect($host,$user,$pass,$db);
>
> if(!$conexao)
>
> die("Error: " . mysqli_error());
>
> mysqli_select_db($conexao,$db) or die("Error: " . mysqli_error());
>
> $SQL = "SELECT * FROM portfolio WHERE id='$id' ORDER BY id DESC LIMIT 1";
>
> $query = mysqli_query($conexao,$SQL);
>
> while($x = mysqli_fetch_array($query)) {
>
> ?>
>
> Thanks a lot.
> "Torsten Rosenberger" <[email protected]> escreveu na mensagem
> news:[email protected]..
>
> Hello
>>
>> Am Montag, den 07.12.2015, 11:07 -0200 schrieb Release Edl:
>>
>>> Hi people,
>>>
>>> How can I use the mysqli function to substitute of mysql ?
>>>
>>> I need to change an old script that uses mysql.
>>>
>>> The script::
>>>
>>> <?php
>>>
>>> include(conexao.php");
>>> $id = $_GET['id'];
>>> $conexao = mysql_connect('host', 'user', 'pass');
>>>
>>> if(!$conexao)
>>>
>>> die("Error: " . mysql_error());
>>>
>>> mysql_select_db($db) or die("Error: " . mysql_error());
>>>
>>> $SQL = "SELECT * FROM portfolio WHERE id='$id' ORDER BY id DESC LIMIT 1";
>>>
>>> $query = mysql_query($SQL);
>>>
>>> while($x = mysql_fetch_array($query)) {
>>>
>>> ?>
>>>
>>
>> http://de.php.net/manual/en/book.mysqli.php
>>
>> take a look in the manual.
>>
>> most functions are the same but with mysqli in front.
>>
>> $link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
>>
>> mysqli_select_db ( $link , $db );
>> mysqli_query ( $link ,.....)
>>
>> so you have to rewrite the mysql with mysqli and add the connection to
>> all other functions
>>
>>
>> BR/Torsten
>>
>>
>>
>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Torsten Rosenberger
Re: [PHP] Deprecated features in PHP 5.5.x
December 07, 2015 04:00PM
Am Montag, den 07.12.2015, 09:33 -0500 schrieb Aziz Saleh:
> mysql_ functions were removed because of insecurities (like in your code,
> you are not escaping your parameters and is very hackable). I would advise
> on using prepared queries in mysqli_ instead of raw queries:
>
> http://php.net/manual/en/mysqli.prepare.php
>
> On Mon, Dec 7, 2015 at 8:44 AM, Release Edl <[email protected]>
> wrote:
>
> > Perfect, Torsten!
> >
> > Now it works properly:
> >
> > <?php
> >
> > include("conexao.php");
> > $id = $_GET['id'];
> > $conexao = mysqli_connect($host,$user,$pass,$db);
> >
> > if(!$conexao)
> >
> > die("Error: " . mysqli_error());
> >
> > mysqli_select_db($conexao,$db) or die("Error: " . mysqli_error());
> >
> > $SQL = "SELECT * FROM portfolio WHERE id='$id' ORDER BY id DESC LIMIT 1";
> >
> > $query = mysqli_query($conexao,$SQL);
> >
> > while($x = mysqli_fetch_array($query)) {
> >
> > ?>
> >
> > Thanks a lot.
> > "Torsten Rosenberger" <[email protected]> escreveu na mensagem
> > news:[email protected]..
> >
> > Hello
> >>
> >> Am Montag, den 07.12.2015, 11:07 -0200 schrieb Release Edl:
> >>
> >>> Hi people,
> >>>
> >>> How can I use the mysqli function to substitute of mysql ?
> >>>
> >>> I need to change an old script that uses mysql.
> >>>
> >>> The script::
> >>>
> >>> <?php
> >>>
> >>> include(conexao.php");
> >>> $id = $_GET['id'];
> >>> $conexao = mysql_connect('host', 'user', 'pass');
> >>>
> >>> if(!$conexao)
> >>>
> >>> die("Error: " . mysql_error());
> >>>
> >>> mysql_select_db($db) or die("Error: " . mysql_error());
> >>>
> >>> $SQL = "SELECT * FROM portfolio WHERE id='$id' ORDER BY id DESC LIMIT 1";
> >>>
> >>> $query = mysql_query($SQL);
> >>>
> >>> while($x = mysql_fetch_array($query)) {
> >>>
> >>> ?>
> >>>
> >>
> >> http://de.php.net/manual/en/book.mysqli.php
> >>
> >> take a look in the manual.
> >>
> >> most functions are the same but with mysqli in front.
> >>
> >> $link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
> >>
> >> mysqli_select_db ( $link , $db );
> >> mysqli_query ( $link ,.....)
> >>
> >> so you have to rewrite the mysql with mysqli and add the connection to
> >> all other functions
> >>
> >>


http://de2.php.net/manual/en/mysqli.real-escape-string.php

or you use this on your normal querys





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Gener Badenas
Re: [PHP] Deprecated features in PHP 5.5.x
December 08, 2015 09:10AM
On Mon, Dec 7, 2015 at 9:07 PM, Release Edl <[email protected]>
wrote:

> Hi people,
>
> How can I use the mysqli function to substitute of mysql ?
>
> I need to change an old script that uses mysql.
>
> The script::
>
> <?php
>
> include(conexao.php");
> $id = $_GET['id'];
> $conexao = mysql_connect('host', 'user', 'pass');
>
> if(!$conexao)
>
> die("Error: " . mysql_error());
>
> mysql_select_db($db) or die("Error: " . mysql_error());
>
> $SQL = "SELECT * FROM portfolio WHERE id='$id' ORDER BY id DESC LIMIT 1";
>
> $query = mysql_query($SQL);
>
> while($x = mysql_fetch_array($query)) {
>
> ?>
>
>

I highly recommend PDO instead of mysql_functions


> Thanks in advance for any help.
>
> Paulo
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
Java http://javadevnotes.com/java-sort-array-examples and Groovy
http://grails.asia/groovy-list-tutorial-and-examples
Release Edl
Re: [PHP] Deprecated features in PHP 5.5.x
February 22, 2017 04:00PM
Hi there,

Torsten gave a good help. Now I'm having a trouble with php 7.1. The script
works properly in php 5.6:

<?php

include("_restrito/conexao.php");

$conexao = mysqli_connect($host,$user,$pass,$db);

if(!$conexao)

die("Nao foi possivel conectar no servidor MySQL. Erro: " .
mysqli_error());

mysqli_select_db($conexao,$db) or die("Nao foi possivel usar o banco de
dados. Erro: " . mysqli_error());

$pagina = $_GET['pagina'];

$banco = mysqli_select_db("mensagem");

$busca = "SELECT * FROM portfolio ORDER BY id DESC";

$total_reg = "5";
if (!$pagina) {
$pc = "1";
} else {
$pc = $pagina;
}

$inicio = $pc - 1;
$inicio = $inicio * $total_reg;

$limite = mysqli_query("$busca LIMIT $inicio,$total_reg");
$todos = mysqli_query("$busca");

$tr = mysqli_num_rows($todos);
$tp = $tr / $total_reg;

while ($dados = mysqli_fetch_array($limite)) {

?>

Could you help?

"Torsten Rosenberger" <[email protected]> escreveu na mensagem
news:[email protected]..
> Hello
>
> Am Montag, den 07.12.2015, 11:07 -0200 schrieb Release Edl:
>> Hi people,
>>
>> How can I use the mysqli function to substitute of mysql ?
>>
>> I need to change an old script that uses mysql.
>>
>> The script::
>>
>> <?php
>>
>> include(conexao.php");
>> $id = $_GET['id'];
>> $conexao = mysql_connect('host', 'user', 'pass');
>>
>> if(!$conexao)
>>
>> die("Error: " . mysql_error());
>>
>> mysql_select_db($db) or die("Error: " . mysql_error());
>>
>> $SQL = "SELECT * FROM portfolio WHERE id='$id' ORDER BY id DESC LIMIT 1";
>>
>> $query = mysql_query($SQL);
>>
>> while($x = mysql_fetch_array($query)) {
>>
>> ?>
>
> http://de.php.net/manual/en/book.mysqli.php
>
> take a look in the manual.
>
> most functions are the same but with mysqli in front.
>
> $link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
>
> mysqli_select_db ( $link , $db );
> mysqli_query ( $link ,.....)
>
> so you have to rewrite the mysql with mysqli and add the connection to
> all other functions
>
>
> BR/Torsten
>
>
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Richard
Re: [PHP] Deprecated features in PHP 5.5.x
February 22, 2017 04:10PM
> Date: Wednesday, February 22, 2017 11:54:07 -0300
> From: Release Edl <[email protected]>
>
> Hi there,
>
> Torsten gave a good help. Now I'm having a trouble with php 7.1.
> The script works properly in php 5.6:
>
> <?php
>
> include("_restrito/conexao.php");
>
> $conexao = mysqli_connect($host,$user,$pass,$db);
>
> if(!$conexao)
>
> die("Nao foi possivel conectar no servidor MySQL. Erro: " .
> mysqli_error());
>
> mysqli_select_db($conexao,$db) or die("Nao foi possivel usar o
> banco de dados. Erro: " . mysqli_error());
>
> $pagina = $_GET['pagina'];
>
> $banco = mysqli_select_db("mensagem");
>
> $busca = "SELECT * FROM portfolio ORDER BY id DESC";
>
> $total_reg = "5";
> if (!$pagina) {
> $pc = "1";
> } else {
> $pc = $pagina;
> }
>
> $inicio = $pc - 1;
> $inicio = $inicio * $total_reg;
>
> $limite = mysqli_query("$busca LIMIT $inicio,$total_reg");
> $todos = mysqli_query("$busca");
>
> $tr = mysqli_num_rows($todos);
> $tp = $tr / $total_reg;
>
> while ($dados = mysqli_fetch_array($limite)) {
>
> ?>
>
> Could you help?
>

Where/what fails? I.e., have you tried debugging it? Have you tried
putting in debug (e.g., print/echo) statements and/or taking it apart
so you know how far it gets and what it is failing (including
relevant values at that point)?


[even though the list is set that way, do *not* include my direct
address in a reply. reply only to the list. thank you.]




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login