How can you insert into the mysql database a string containing the *

2

I'm using PHP and Mysql and I'm trying to add a NEXTEL and CLARO type radio ID field:

23*4567

But when I check what has been inserted, I see that it only registered what is before *, thus:

23

Using a normal query like this:

INSERT INTO tabela (id_radio) VALUES ("23*4567")

I've tried using the functions, but nothing worked.

addslashes()
mysql_real_scape_string()

Is there a function required for * to be accepted by mysql?

    
asked by anonymous 06.03.2014 / 21:55

4 answers

2

Simply change the field type to varchar and insert as string into the field.

    
06.03.2014 / 23:00
1

If you use a parameterized query the bank will be able to insert special characters without any problem. You only have to escape the values if you are creating the query in hand, with fixed literals.

//$dbh é a sua conexão com o BD.
$stmt = $dbh->prepare("INSERT INTO tabela (id_radio) VALUES (?)");
$stmt->execute(array("23*4567"))
    
06.03.2014 / 22:09
1
If the field that has the radius number is numeric (int, float, numeric) switch it to varchar , this also eliminates the problem of some number that starts with zero because they are removed when they are to the left.

The code to change the column type is this:

ALTER TABLE tabela MODIFY  campo varchar(50)

I made a test create a table with two columns and I executed this insert directly in the bank

INSERT INTO radios(radio_int, radio_varchar) values(23*4567, '23*4567')

the result was

radio_int: 105041
radio_varchar: 23*4567
    
06.03.2014 / 22:47
0

Try to send the char of the character * rather than the character itself for example:

INSERT INTO tabela (id_radio) VALUES ("23".CHAR(42)."4567")
    
06.03.2014 / 22:05