Solved

PHP PDO Safe string

Posted on 2016-10-04
2
21 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 108

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 108

Expert Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
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 count occurrences of each item in an array.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now