Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP PDO Safe string

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
The viewer will learn how to count occurrences of each item in an array.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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