Solved

PHP PDO Safe string

Posted on 2016-10-04
2
39 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 110

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 110

Expert Comment

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

624 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