Solved

PHP PDO Safe string

Posted on 2016-10-04
2
29 Views
Last Modified: 2016-10-23
Im trying to backup my SQL databases (as cant connect remotly to do a backup, and cant use mysqldump), and I have the values from the database, but I want to store them safely in a text file, which means escaping characters such as "\n".

My initial ideal was to use str_replace, but I could be here for ages doing it. Then I thought about converting the string to hex codes and using that, but it seems a bit messy.

What I really want to do is do something like :-
<?php

$strOutput = <<<EOD
This is a 
test with a % character.
EOD;

echo mysqli::real_escape_string($strOutput);

?>

Open in new window


But all I get is:-
E_ERROR : type 1 -- Non-static method mysqli::real_escape_string() cannot be called statically -- at line 8

Any suggestions?
0
Comment
Question by:tonelm54
  • 2
2 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points (awarded by participants)
ID: 41828075
Instantiate a MySQLi object, then call the method with non-static OOP notation.  Something like this:

$x = new MySQLi( ... );
$y = $x->real_escape_string($strOutput);
echo $y;

Open in new window

Examples of correct usage are available in this article:
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 41855864
Non-static methods require an object instance.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question