Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP PDO Safe string

Posted on 2016-10-04
2
Medium Priority
?
46 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

877 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